/*
RetroLeague - Mobile application for The Retro League Podcast
Copyright (C) 2010-2012 Hugues Johnson

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

package com.huguesjohnson.retroleague.forums;

import java.util.ArrayList;

import com.huguesjohnson.retroleague.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ForumPostArrayAdapter extends ArrayAdapter<ForumPost>{
	private Context context;
	private int resourceId;
	private ArrayList<ForumPost> forumPosts;

	public ForumPostArrayAdapter(Context context,int resourceId,ArrayList<ForumPost> forumPosts){
		super(context,resourceId,(ForumPost[])forumPosts.toArray(new ForumPost[forumPosts.size()]));
		this.context=context;
		this.resourceId=resourceId;
		this.forumPosts=forumPosts;
	}
	
	@Override
	public View getView(int position,View convertView,ViewGroup parent){
		LayoutInflater inflater=(LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View layout=inflater.inflate(resourceId,null);
		TextView title=(TextView)layout.findViewById(R.id.listitem_forumpost_title);
		title.setText(this.forumPosts.get(position).getTitle());
		TextView postedDate=(TextView)layout.findViewById(R.id.listitem_forumpost_date);
		postedDate.setText(this.forumPosts.get(position).getPostedDate());
		TextView author=(TextView)layout.findViewById(R.id.listitem_forumpost_author);
		author.setText(this.forumPosts.get(position).getAuthor());
		return(layout);
	}
}
